﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using XLSupermarket.MainInterface;
using XLSupermarket.Properties;
using XLSupermarket.Cashier;
using Supermarket;
using XLSupermarket.Financial;
using XLSupermarket.Storehouse;
using XLSupermarket.MainInterface.SuperAdmin;

namespace XLSupermarket.MainInterface
{
    public partial class MainForm : Form
    {
        public static string UserName;//用户姓名
        public MainForm()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 打开收银界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BT_POS_Click(object sender, EventArgs e)
        {
            Cashier.Cashier cashier = new Cashier.Cashier();
            this.Hide();
            cashier.Show();
        }
        /// <summary>
        /// 点击退出按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("您确认退出吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result == DialogResult.OK) System.Environment.Exit(0);
        }
        /// <summary>
        /// 退出时的确认
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult result = MessageBox.Show("您确认退出吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result == DialogResult.Cancel) e.Cancel = true;
            else Environment.Exit(0);
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            timer1.Start();//时钟的Timer
            UserName = LoginForm.UserName_Value;
            string sql = "select EP_Name from EP_information ei,EP_Number en where ei.EP_ID = en.EP_ID and UserName = '"+UserName+"'";
            DataTable dt = DBHelper.FillData(sql);//查看名字
            string EP_Name = dt.Rows[0][0].ToString();
            label2.Text = EP_Name;
            //MessageBox.Show();
        }
        /// <summary>
        /// 时间实时显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Lable_Time.Text = DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss");
        }

        private void BT_Finance_Click(object sender, EventArgs e)
        {
            FinancialForm ff = new FinancialForm();
            this.Hide();
            ff.Show();
        }

        private void BT_Wh_Click(object sender, EventArgs e)
        {
            Storehouse.Storehouse sh = new Storehouse.Storehouse();
            this.Hide();
            sh.Show();
        }

        private void BT_Gs_Click(object sender, EventArgs e)
        {
            SuperAdminForm saf = new SuperAdminForm();
            saf.ShowDialog();
        }

        private void BT_Exit_Click(object sender, EventArgs e)
        {
            LoginForm LF = new LoginForm();
            this.Hide();
            LF.Show();
        }

        private void BT_Admin_Click(object sender, EventArgs e)
        {
            Admin.AdminForm AA = new Admin.AdminForm();
            this.Hide();
            AA.Show();
        }
    }
}
